﻿<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8">
    <title>上传测试</title>
    <script type="text/javascript" src="js/cos-js-sdk-v5.js"></script>
    <script type="text/javascript">
		//实例化COS对象
        var cos = new COS({
            SecretId: '{{key_id}}', //密钥id
            SecretKey: '{{key_key}}'//密钥的key
        });
        console.log("上传文件-HTML-JS版本")
        //点击上传按钮上传文件到腾讯云
        function uploadCos() {
            var file = document.getElementById('upload_file').files[0];
            cos.putObject({
                Bucket: '{{bucket}}', // 桶名-APPID  必须
                Region: '{{region}}', //区域 必须
                Key: '{{key}}', //文件名必须
                StorageClass: 'STANDARD',
                Body: file, // 上传文件对象
                onProgress: function (progressData) {
                    console.log(JSON.stringify(progressData));//上传成功的返回值
                }
            }, function (err, data) {
                console.log(err || data);//上传失败的返回值
            });
        }
    </script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
请选择文件:<input type="file" id="upload_file" value=""/>
<input type="button" value="上传" onclick="uploadCos()"/>
</body>
</html>
